package com.weixin.paleituo.factory;

import android.support.v4.app.Fragment;

import com.weixin.paleituo.fragment.AfterSaleRecord;
import com.weixin.paleituo.fragment.AfterSaleReques;
import com.weixin.paleituo.util.LogUtils;

import java.util.HashMap;

/**
 * Author yichao
 * Time  2017/11/30 9:36
 * Dest  售后fragment的工厂
 */

public class AfterSaleFragmentFactory {
    public static String TAG="AfterSaleFragmentFactory";
    private static final int AFTER_SALE_REQUEST_FRAGMENT = 0;
    private static final int AFTER_SALE_RECORD_FRAGMENT = 1;
    private static HashMap<Integer,Fragment> mMap=new HashMap();


    public static Fragment getFragment(int index) {
        Fragment fragment=null;
        if (mMap.containsKey(index)){
            fragment=   mMap.get(index);
            LogUtils.i(TAG,"复用"+index);

        }else {
            switch (index) {
                case AFTER_SALE_REQUEST_FRAGMENT:
                    fragment =  AfterSaleReques.newInstance();
                    break;
                case AFTER_SALE_RECORD_FRAGMENT:
                    fragment =  AfterSaleRecord.newInstance();
                    break;
            }
            LogUtils.i(TAG,"新建"+index);
            mMap.put(index,fragment);
        }
        return fragment;

    }


}
